package com.example.kugou.service.serviceimpl;

import com.example.kugou.common.music.FileUtils;
import com.example.kugou.common.music.Mp3Info;
import com.example.kugou.common.time.TimeAdd;
import com.example.kugou.mapper.SingMapper;
import com.example.kugou.mapper.SingerMapper;
import com.example.kugou.pojo.Sing;
import com.example.kugou.pojo.Singer;
import com.example.kugou.service.SingService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.File;
import java.util.List;

@Service("singService")
public class SingServiceImpl implements SingService {

    @Resource
    SingMapper singMapper;

    @Resource
    SingerMapper singerMapper;

    public SingMapper getSingMapper() {
        return singMapper;
    }

    public void setSingMapper(SingMapper singMapper) {
        this.singMapper = singMapper;
    }


    @Override
    public Sing selectById(int id) {
        return singMapper.selectById(id);
    }

    @Override
    public List<Sing> SelectSing() {
        return singMapper.SelectSing();
    }

    @Override
    public List<Sing> SelectAllSing(String SingName) {
        return singMapper.SelectAllSing(SingName);
    }

    @Override
    public List<Sing> SelectByFirstTen() {
        return singMapper.SelectByFirstTen();
    }

    @Override
    public List<Sing> SelectByCenterTen() {
        return singMapper.SelectByCenterTen();
    }

    @Override
    public List<Sing> selectByLastTen() {
        return singMapper.selectByLastTen();
    }

    @Override
    public Sing selectSingById(int id) {
        return singMapper.selectSingById(id);
    }

    @Override
    public List<Sing> selectNewSings() {
        TimeAdd.nowAddMonth(-1);
        return singMapper.selectNewSings(TimeAdd.getDate());
    }

    @Override
    public List<Sing> selectBysong_sheetid(int song_sheetid) {
        return singMapper.selectBysong_sheetid(song_sheetid);
    }

    @Override
    public List<Sing> selectSingsOrderByTime() {
        return singMapper.selectSingsOrderByTime();
    }

    @Override
    public List<Sing> selectOrderById() {
        return singMapper.selectOrderById();
    }

    @Override
    public List<Sing> selectPaiHang() {
        return singMapper.selectPaiHang();
    }

    @Override
    public int deleteBySing(Integer nid) {
        return singMapper.deleteBySing(nid);
    }

    @Override
    public int insertSing(Sing sing) {
        return singMapper.insertSing(sing);
    }

    @Override
    public List<Sing> selectName(String name) {
        System.out.println(name);
        return singMapper.selectName(name);
    }


    //增加歌曲
    public void insertSings() {
        File file = new File("E:\\小组项目\\网易云\\网易云\\Music.163-Web_wangyiyunyinyue\\audio");
        List<Mp3Info> mp3Info = null;
        Sing sing = new Sing();
        Singer singer = new Singer();
        Mp3Info music1 = new Mp3Info();
        try {
            mp3Info = FileUtils.getAllMuInfo(file);
            for (int i = 0 ;i < mp3Info.size();i++ ){
                music1 = mp3Info.get(i);
                sing.setMusic(music1);
                sing.setType(2);
                singer = singerMapper.selectByName(music1.getSingerName());
                if (singer != null && singer.getRid() > 0){
                    sing.setSingerId(singer.getRid());
                }else {
                    int count = singerMapper.insertSinger(new Singer(music1.getSongName()));
                    System.out.println(count);
                }
                System.out.println(sing);
                int count = singMapper.insertSing(sing);
                System.out.println(count);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }


    }
}
